<?php

namespace yan\backendclient\modules\backendlanguage\models;

use Yii;

/**
 * This is the model class for table "{{%backend_language}}".
 *
 * @property integer $id
 * @property string $code
 * @property integer $status
 * @property string $name
 * @property integer $sort_order
 */
class BackendLanguage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%backend_language}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['code'], 'required'],
            [['status', 'sort_order'], 'integer'],
            [['code'], 'string', 'max' => 8],
            [['name'], 'string', 'max' => 255],
            [['code'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('debug', 'ID'),
            'code' => Yii::t('debug', 'Code'),
            'status' => Yii::t('debug', 'Status'),
            'name' => Yii::t('debug', 'Name'),
            'sort_order' => Yii::t('debug', 'Sort Order'),
        ];
    }

    // 查找多語言列表
    public function findLanguageCode(){
        $path = Yii::getAlias('@backend/messages');
        $data = [];
        $data['en-US'] = 'en-US';

        if( is_dir($path) ){
            $dp = dir($path);

            
            while($file=$dp->read()){

                if($file!='.'&& $file!='..'){

                    if( is_dir( $path. DS .$file) ){
                        $data[$file] = $file;
                    }
                }
            }
            $dp->close();
        }
        return $data;
    }
}
